#include "eveCommon.h"
#include "eveConstantVertexBuffer.h"


DWORD c_ConstantVB_fvf = D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1;
Singleton_Source(ConstantVertexBuffer);
ConstantVertexBuffer::ConstantVertexBuffer()
: D3DVertexBuffer(sizeof(stVertex),4,c_ConstantVB_fvf,D3DPT_TRIANGLESTRIP,D3DUSAGE_DYNAMIC)
{

}

void ConstantVertexBuffer::Fill(const stRectI&rc,DWORD color,const stRectF& texturerc)
{
	static stVertex v[4];
	v[0].v = D3DXVECTOR4(rc.left,rc.top,0.0f,1.0f);
	v[0].color = color;
	v[0].uv = D3DXVECTOR2(texturerc.left,texturerc.top);
	
	v[1].v = D3DXVECTOR4(rc.right,rc.top,0.0f,1.0f);
	v[1].color = color;
	v[1].uv = D3DXVECTOR2(texturerc.right,texturerc.top);

	v[2].v = D3DXVECTOR4(rc.left,rc.bottom,0.0f,1.0f);
	v[2].color = color;
	v[2].uv = D3DXVECTOR2(texturerc.left,texturerc.bottom);

	v[3].v = D3DXVECTOR4(rc.right,rc.bottom,0.0f,1.0f);
	v[3].color = color;
	v[3].uv = D3DXVECTOR2(texturerc.right,texturerc.bottom);

	BYTE* pData = this->Lock(0,sizeof(v),D3DLOCK_DISCARD);
	memcpy(pData,v,sizeof(v));
	this->unLock();

}